package com.itheima;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;

public class Server {
    //定义一个静态集合
    public static Map<Socket,String> allSocketOnLine=new HashMap<>();
    public static void main(String[] args) {
        try{
            ServerSocket ss=new ServerSocket(9999);
            while(true){
                Socket socket=ss.accept();
                //把登录的客户端socket存入到一个在线线程中去
                Scanner sc=new Scanner(System.in);
                System.out.println("请输入用户名");
                String name=sc.nextLine();
                allSocketOnLine.put(socket,name);
                //为当前登录成功的socket分配一个独立的线程来处理与之通信
                new ServerReaderThread(socket).start();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
